import mysql from 'mysql2/promise';
import { DB_USER, DB_PASSWORD, DB_HOST, DB_NAME} from '@/config/settings';

const pool = mysql.createPool({
  host: DB_HOST || process.env.DB_HOST,
  user: DB_USER || process.env.DB_USER,
  password: DB_PASSWORD || process.env.DB_NAME,
  database: DB_NAME || process.env.DB_NAME,
  waitForConnections: true,
  connectionLimit: 8,
  maxIdle: 2, 
  idleTimeout: 10000, 
  queueLimit: 20, 
  enableKeepAlive: true,
  keepAliveInitialDelay: 0,
});

pool.on('error', (err) => {
  console.error('Unexpected error on idle client', err);
});

export default pool